home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / reportplus / source / f7.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-27  |  24.1 KB  |  684 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <intuition/intuition.h>
  4. #include <intuition/gadgetclass.h>
  5. #include <libraries/gadtools.h>
  6. #include <dos/dosextens.h>
  7. #include <graphics/gfx.h>
  8.  
  9. #include <clib/exec_protos.h>
  10. #include <clib/intuition_protos.h>
  11. #include <clib/gadtools_protos.h>
  12. #include <clib/dos_protos.h>
  13. #include <clib/graphics_protos.h>
  14.  
  15. #define ALL_REACTION_CLASSES
  16. #define ALL_REACTION_MACROS
  17. #include <reaction/reaction.h>
  18.  
  19. #include <ctype.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include "rp.h"
  23.  
  24. #define AMIGA 0
  25. #define MAC   1
  26. #define IBM   2
  27.  
  28. // from rp.c
  29. IMPORT TEXT                IOBuffer[LONGESTFIELD + 1];
  30. IMPORT ABOOL               fillwindows, stop;
  31. IMPORT SBYTE               page;
  32. IMPORT SWORD               y;
  33. IMPORT TEXT                asldir[PATHNAMEFIELD + 1];
  34. IMPORT ULONG               fillcolour;
  35. IMPORT struct NewGadget    Gadget;
  36. IMPORT struct Window*      MainWindowPtr;
  37. IMPORT struct Screen*      ScreenPtr;
  38. IMPORT struct IconBase*    IconBase;
  39. IMPORT struct SharedStruct shared;
  40. IMPORT Object*             WinObject[FUNCTIONS + 1];
  41. IMPORT struct Menu*        MenuPtr;
  42.  
  43. MODULE struct
  44. {   ULONG detabulate, unwrap, source, dest, tabsize;
  45.     TEXT  pathname[PATHNAMEFIELD + 1];
  46. } eol =
  47. {   FALSE, FALSE, IBM, AMIGA, 8, ""
  48. };
  49.  
  50. AGLOBAL struct Gadget* eol_gadgets[GIDS_7 + 1];
  51.  
  52. MODULE STRPTR EOLOptions[4] =
  53. {   (STRPTR) "LF (Amiga)",
  54.     (STRPTR) "CR (Macintosh)",
  55.     (STRPTR) "CR+LF (IBM-PC)",
  56.     NULL
  57. };
  58.  
  59. MODULE ABOOL spaceeol(TEXT nextchar);
  60.  
  61. AGLOBAL void eol1(void)
  62. {   struct Hook Hook7Struct;
  63.  
  64.     InitHook(&Hook7Struct, Hook7Func, NULL);
  65.  
  66.     /* Create the window object. */
  67.     lockscreen();
  68.     if (!(WinObject[7] =          NewObject(WINDOW_GetClass(), NULL,
  69.     // window
  70.     WA_PubScreen,                 ScreenPtr,
  71.     WA_ScreenTitle,               "Report+",
  72.     WA_Title,                     "Report+: EOL/Tab Converter",
  73.     WA_Activate,                  TRUE,
  74.     WA_DepthGadget,               TRUE,
  75.     WA_DragBar,                   TRUE,
  76.     WA_CloseGadget,               TRUE,
  77.     WA_SizeGadget,                TRUE,
  78.     WA_IDCMP,                     IDCMP_RAWKEY,
  79.     WINDOW_IDCMPHook,             &Hook7Struct,
  80.     WINDOW_IDCMPHookBits,         IDCMP_RAWKEY,
  81.     WINDOW_MenuStrip,             MenuPtr,
  82.     WINDOW_Position,              WPOS_CENTERSCREEN,
  83.     WINDOW_ParentGroup,           eol_gadgets[GID_7_LY1] =
  84.                                   NewObject(LAYOUT_GetClass(), NULL,
  85.         // root-layout
  86.         LAYOUT_Orientation,       LAYOUT_ORIENT_VERT,
  87.         LAYOUT_SpaceOuter,        TRUE,
  88.         LAYOUT_DeferLayout,       TRUE,
  89.         LAYOUT_AddChild,
  90.         NewObject
  91.         (   LAYOUT_GetClass(),    NULL,
  92.             LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  93.             LAYOUT_VertAlignment, LALIGN_CENTER,
  94.             LAYOUT_HorizAlignment,LALIGN_CENTER,
  95.             LAYOUT_BevelStyle,    BVS_NONE,
  96.             LAYOUT_AddChild,
  97.             NewObject
  98.             (   LAYOUT_GetClass(),    NULL,
  99.                 LAYOUT_Orientation,   LAYOUT_ORIENT_VERT,
  100.                 LAYOUT_SpaceOuter,    TRUE,
  101.                 LAYOUT_VertAlignment, LALIGN_CENTER,
  102.                 LAYOUT_HorizAlignment,LALIGN_CENTER,
  103.                 LAYOUT_BevelStyle,    BVS_FIELD,
  104.                 LAYOUT_AddImage,          NewObject
  105.                 (   LABEL_GetClass(),     NULL,
  106.                     LABEL_Text,           "_Source:",
  107.                     LABEL_Justification,  LJ_CENTER,
  108.                 TAG_END),
  109.                 CHILD_WeightedHeight,     0,
  110.                 LAYOUT_AddChild,          eol_gadgets[GID_7_RA1] =
  111.                 NewObject
  112.                 (   RADIOBUTTON_GetClass(),NULL,
  113.                     GA_ID,                GID_7_RA1,
  114.                     GA_RelVerify,         TRUE,
  115.                     GA_Text,              EOLOptions,
  116.                     RADIOBUTTON_Selected, (WORD) eol.source,
  117.                 TAG_END),
  118.             TAG_END),
  119.             CHILD_WeightedWidth,      50,
  120.             LAYOUT_AddChild,
  121.             NewObject
  122.             (   LAYOUT_GetClass(),    NULL,
  123.                 LAYOUT_Orientation,   LAYOUT_ORIENT_VERT,
  124.                 LAYOUT_SpaceOuter,    TRUE,
  125.                 LAYOUT_VertAlignment, LALIGN_CENTER,
  126.                 LAYOUT_HorizAlignment,LALIGN_CENTER,
  127.                 LAYOUT_BevelStyle,    BVS_FIELD,
  128.                 LAYOUT_AddImage,          NewObject
  129.                 (   LABEL_GetClass(),     NULL,
  130.                     LABEL_Text,           "_Destination:",
  131.                     LABEL_Justification,  LJ_CENTER,
  132.                 TAG_END),
  133.                 CHILD_WeightedHeight,     0,
  134.                 LAYOUT_AddChild,          eol_gadgets[GID_7_RA2] =
  135.                 NewObject
  136.                 (   RADIOBUTTON_GetClass(),NULL,
  137.                     GA_ID,                GID_7_RA2,
  138.                     GA_RelVerify,         TRUE,
  139.                     GA_Text,              EOLOptions,
  140.                     RADIOBUTTON_Selected, (WORD) eol.dest,
  141.                 TAG_END),
  142.             TAG_END),
  143.             CHILD_WeightedWidth,      50,
  144.         TAG_END),
  145.         LAYOUT_AddChild,
  146.         NewObject
  147.         (   LAYOUT_GetClass(),    NULL,
  148.             LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  149.             LAYOUT_VertAlignment, LALIGN_CENTER,
  150.             LAYOUT_HorizAlignment,LALIGN_CENTER,
  151.             LAYOUT_BevelStyle,    BVS_NONE,
  152.             LAYOUT_AddChild,          eol_gadgets[GID_7_CB1] =
  153.             NewObject
  154.             (   CHECKBOX_GetClass(),  NULL,
  155.                 GA_ID,                GID_7_CB2,
  156.                 GA_RelVerify,         TRUE,
  157.                 GA_Text,              "C_onvert tabs to spaces?",
  158.                 GA_Selected,          (BOOL) eol.detabulate,
  159.             TAG_END),
  160.             CHILD_WeightedWidth,      0,
  161.             LAYOUT_AddImage,
  162.             NewObject
  163.             (   LABEL_GetClass(),     NULL,
  164.                 LABEL_Text,           "",
  165.             TAG_END),
  166.             CHILD_WeightedWidth,      100,
  167.             LAYOUT_AddImage,
  168.             NewObject
  169.             (   LABEL_GetClass(),     NULL,
  170.                 LABEL_Text,           "_Tab size:",
  171.             TAG_END),
  172.             CHILD_WeightedWidth,      0,
  173.             LAYOUT_AddChild,          eol_gadgets[GID_7_IN1] =
  174.             NewObject
  175.             (   INTEGER_GetClass(),   NULL,
  176.                 GA_ID,                GID_7_IN1,
  177.                 GA_RelVerify,         TRUE,
  178.                 GA_TabCycle,          TRUE,
  179.                 INTEGER_Number,       eol.tabsize,
  180.                 INTEGER_Minimum,      0,
  181.                 INTEGER_Maximum,      99,
  182.                 INTEGER_MinVisible,   2,
  183.             TAG_END),
  184.             CHILD_WeightedWidth,      0,
  185.         TAG_END), 
  186.         CHILD_WeightedHeight,         0,
  187.         LAYOUT_AddChild,              eol_gadgets[GID_7_CB2] =
  188.         NewObject
  189.         (   CHECKBOX_GetClass(),      NULL,
  190.             GA_ID,                    GID_7_CB2,
  191.             GA_RelVerify,             TRUE,
  192.             GA_Text,                  "_Unwrap words?",
  193.             GA_Selected,              (BOOL) eol.unwrap,
  194.         TAG_END),
  195.         CHILD_WeightedHeight,         0,
  196.         LAYOUT_AddChild,
  197.         NewObject
  198.         (   LAYOUT_GetClass(),        NULL,
  199.             LAYOUT_Orientation,       LAYOUT_ORIENT_HORIZ,
  200.             LAYOUT_VertAlignment,     LALIGN_CENTER,
  201.             LAYOUT_HorizAlignment,    LALIGN_CENTER,
  202.             LAYOUT_BevelStyle,        BVS_NONE,
  203.             LAYOUT_AddImage,
  204.             NewObject
  205.             (   LABEL_GetClass(),     NULL,
  206.                 LABEL_Text,           "_Pathname(s):",
  207.                 LABEL_Justification,  LJ_LEFT,
  208.             TAG_END),
  209.             LAYOUT_AddChild,          eol_gadgets[GID_7_ST1] =
  210.             NewObject
  211.             (   STRING_GetClass(),    NULL,
  212.                 GA_ID,                GID_7_ST1,
  213.                 GA_RelVerify,         TRUE,
  214.                 STRINGA_TextVal,      eol.pathname,
  215.                 STRINGA_MinVisible,   20,
  216.             TAG_END),
  217.             LAYOUT_AddChild,      eol_gadgets[GID_7_BU1] =
  218.             NewObject
  219.             (   NULL,             "button.gadget",
  220.                 GA_ID,            GID_7_BU1,
  221.                 GA_RelVerify,     TRUE,
  222.                 BUTTON_AutoButton,BAG_POPFILE,
  223.             TAG_END),
  224.             CHILD_WeightedWidth,  0,
  225.         TAG_END),
  226.         CHILD_WeightedHeight,     0,
  227.         LAYOUT_AddChild,          eol_gadgets[GID_7_ST2] =
  228.         NewObject
  229.         (   STRING_GetClass(),    NULL,
  230.             GA_ReadOnly,          TRUE,
  231.             GA_ID,                GID_7_ST2,
  232.             STRINGA_TextVal,      "Ready.",
  233.         TAG_END),
  234.         CHILD_WeightedHeight,     0,
  235.         LAYOUT_AddChild,
  236.         NewObject
  237.         (   LAYOUT_GetClass(),    NULL,
  238.             LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  239.             LAYOUT_VertAlignment, LALIGN_CENTER,
  240.             LAYOUT_HorizAlignment,LALIGN_CENTER,
  241.             LAYOUT_BevelStyle,    BVS_NONE,
  242.             LAYOUT_AddChild,      eol_gadgets[GID_7_BU3] =
  243.                                   NewObject(NULL, "button.gadget",
  244.                 GA_ID,            GID_7_BU3,
  245.                 GA_RelVerify,     TRUE,
  246.                 GA_Text,          "Pro_cess",
  247.             TAG_END),
  248.             CHILD_WeightedWidth,  50,
  249.             LAYOUT_AddChild,      eol_gadgets[GID_7_BU4] =
  250.                                   NewObject(NULL, "button.gadget",
  251.                 GA_ID,            GID_7_BU4,
  252.                 GA_RelVerify,     TRUE,
  253.                 GA_Text,          "Stop",
  254.                 GA_Disabled,      TRUE,
  255.             TAG_END),
  256.             CHILD_WeightedWidth,  50,
  257.         TAG_END),
  258.         CHILD_WeightedHeight,     0,
  259.     TAG_END)
  260.     )))
  261.     {   rq("Can't create ReAction objects!");
  262.     }
  263.     unlockscreen();
  264.     openwindow();
  265.     ActivateLayoutGadget(eol_gadgets[GID_7_LY1], MainWindowPtr, NULL, (Object) eol_gadgets[GID_7_ST1]);
  266.  
  267.     loop();
  268.     closewindow();
  269. }
  270.  
  271. AGLOBAL void eol_do(void)
  272. {   STRPTR stringptr;
  273.     ABOOL  anyfound;
  274.  
  275.     if (!(GetAttr
  276.     (   STRINGA_TextVal, eol_gadgets[GID_7_ST1], (ULONG *) &stringptr
  277.     )))
  278.     {   rq("Unsupported inquiry!"); // should never happen
  279.     }
  280.     strcpy(eol.pathname, stringptr);
  281.     if (!(GetAttr
  282.     (   INTEGER_Number, eol_gadgets[GID_7_IN1], (ULONG *) &eol.tabsize
  283.     )))
  284.     {   rq("Unsupported inquiry!"); // should never happen
  285.     }
  286.  
  287.     SetGadgetAttrs
  288.     (   eol_gadgets[GID_7_BU4], MainWindowPtr, NULL,
  289.         GA_Disabled, FALSE,
  290.     TAG_END);
  291.     SetGadgetAttrs
  292.     (   eol_gadgets[GID_7_RA1], MainWindowPtr, NULL,
  293.         GA_Disabled, TRUE,
  294.     TAG_END);
  295.     SetGadgetAttrs
  296.     (   eol_gadgets[GID_7_RA2], MainWindowPtr, NULL,
  297.         GA_Disabled, TRUE,
  298.     TAG_END);
  299.     SetGadgetAttrs
  300.     (   eol_gadgets[GID_7_ST1], MainWindowPtr, NULL,
  301.         GA_Disabled, TRUE,
  302.     TAG_END);
  303.     SetGadgetAttrs
  304.     (   eol_gadgets[GID_7_BU1], MainWindowPtr, NULL,
  305.         GA_Disabled, TRUE,
  306.     TAG_END);
  307.     SetGadgetAttrs
  308.     (   eol_gadgets[GID_7_CB1], MainWindowPtr, NULL,
  309.         GA_Disabled, TRUE,
  310.     TAG_END);
  311.     SetGadgetAttrs
  312.     (   eol_gadgets[GID_7_CB2], MainWindowPtr, NULL,
  313.         GA_Disabled, TRUE,
  314.     TAG_END);
  315.     SetGadgetAttrs
  316.     (   eol_gadgets[GID_7_IN1], MainWindowPtr, NULL,
  317.         GA_Disabled, TRUE,
  318.     TAG_END);
  319.     SetGadgetAttrs
  320.     (   eol_gadgets[GID_7_BU3], MainWindowPtr, NULL,
  321.         GA_Disabled, TRUE,
  322.     TAG_END);
  323.  
  324.     strcpy(shared.pathname, eol.pathname);
  325.     anyfound = convert(TRUE);
  326.     strcpy(eol.pathname, shared.pathname);
  327.  
  328.     if (!stop)
  329.     {   if (anyfound)
  330.         {   SetGadgetAttrs
  331.             (   eol_gadgets[GID_7_ST2], MainWindowPtr, NULL,
  332.                 STRINGA_TextVal, "All done.",
  333.             TAG_END);
  334.         } else
  335.         {   SetGadgetAttrs
  336.             (   eol_gadgets[GID_7_ST2], MainWindowPtr, NULL,
  337.                 STRINGA_TextVal, "No matches!",
  338.             TAG_END);
  339.     }   }
  340.     SetGadgetAttrs
  341.     (   eol_gadgets[GID_7_BU4], MainWindowPtr, NULL,
  342.         GA_Disabled, TRUE,
  343.     TAG_END);
  344.     SetGadgetAttrs
  345.     (   eol_gadgets[GID_7_RA1], MainWindowPtr, NULL,
  346.         GA_Disabled, FALSE,
  347.     TAG_END);
  348.     SetGadgetAttrs
  349.     (   eol_gadgets[GID_7_RA2], MainWindowPtr, NULL,
  350.         GA_Disabled, FALSE,
  351.     TAG_END);
  352.     SetGadgetAttrs
  353.     (   eol_gadgets[GID_7_ST1], MainWindowPtr, NULL,
  354.         GA_Disabled, FALSE,
  355.     TAG_END);
  356.     SetGadgetAttrs
  357.     (   eol_gadgets[GID_7_BU1], MainWindowPtr, NULL,
  358.         GA_Disabled, FALSE,
  359.     TAG_END);
  360.     SetGadgetAttrs
  361.     (   eol_gadgets[GID_7_CB1], MainWindowPtr, NULL,
  362.         GA_Disabled, FALSE,
  363.     TAG_END);
  364.     SetGadgetAttrs
  365.     (   eol_gadgets[GID_7_CB2], MainWindowPtr, NULL,
  366.         GA_Disabled, FALSE,
  367.     TAG_END);
  368.     SetGadgetAttrs
  369.     (   eol_gadgets[GID_7_IN1], MainWindowPtr, NULL,
  370.         GA_Disabled, FALSE,
  371.     TAG_END);
  372.     SetGadgetAttrs
  373.     (   eol_gadgets[GID_7_BU3], MainWindowPtr, NULL,
  374.         GA_Disabled, FALSE,
  375.     TAG_END);
  376. }
  377.  
  378. AGLOBAL void eolconvert(ABOOL gui)
  379. {   ULONG                gap, i, j, cursorx = 0;
  380.     ABOOL                ok                 = TRUE;
  381.     struct FileInfoBlock InputInfoBlock;
  382.     UBYTE*               InputBufferPtr; // always use UBYTE not APTR for pointer arithmetic
  383.     BPTR                 FileHandle;
  384.     TEXT                 saystring[PATHNAMEFIELD + 1];
  385.  
  386.     strcpy(saystring, "Converting ");
  387.     strcat(saystring, shared.thisfile);
  388.     strcat(saystring, "...");
  389.     if (gui)
  390.     {   SetGadgetAttrs
  391.         (   eol_gadgets[GID_7_ST2], MainWindowPtr, NULL,
  392.             STRINGA_TextVal, saystring,
  393.         TAG_END);
  394.     } else
  395.     {   Printf("%s", saystring);
  396.         Flush(Output());
  397.     }
  398.  
  399.     if (FileHandle = (BPTR) Lock(shared.thisfile, ACCESS_READ))
  400.     {   if (Examine(FileHandle, &InputInfoBlock))
  401.         {   UnLock(FileHandle);
  402.             // FileHandle = NULL;
  403.             if (InputInfoBlock.fib_DirEntryType == -3) // if a file
  404.             {   // if it is a directory, we would ideally like to convert all
  405.                 // files in that directory. We also should support links.
  406.                 if (InputBufferPtr = AllocMem(InputInfoBlock.fib_Size, MEMF_ANY | MEMF_PUBLIC))
  407.                 {   if (FileHandle = (BPTR) Open(shared.thisfile, MODE_OLDFILE))
  408.                     {   if (Read(FileHandle, InputBufferPtr, InputInfoBlock.fib_Size) != -1)
  409.                         {   Close(FileHandle);
  410.                             if (FileHandle = (BPTR) Open(shared.thisfile, MODE_NEWFILE))
  411.                             {   for (i = 0; i < InputInfoBlock.fib_Size; i++)
  412.                                 {   if (*(InputBufferPtr + i) == LF)
  413.                                     {   if (eol.unwrap && (eol.source == AMIGA || eol.source == IBM) && spaceeol(*(InputBufferPtr + i + 1)))
  414.                                         {   cursorx++;
  415.                                             FPutC(FileHandle, ' ');
  416.                                         } else
  417.                                         {   cursorx = 0;
  418.  
  419.                                             if (eol.source == eol.dest)
  420.                                                 FPutC(FileHandle, LF); // pass it through
  421.                                             elif (eol.source == AMIGA && eol.dest == IBM)
  422.                                             {   FPutC(FileHandle, CR); // add this
  423.                                                 FPutC(FileHandle, LF); // and pass this through
  424.                                             } elif (eol.source == AMIGA && eol.dest == MAC)
  425.                                                 FPutC(FileHandle, CR); // convert from LF to CR
  426.                                             elif (eol.source == IBM && eol.dest == AMIGA)
  427.                                                 FPutC(FileHandle, LF); // pass it through
  428.                                             elif (eol.source == IBM && eol.dest == MAC)
  429.                                                 ; // do nothing
  430.                                             else ; // mac as source: we never expect LFs
  431.                                     }   }
  432.                                     elif (*(InputBufferPtr + i) == CR)
  433.                                     {   if (eol.unwrap && eol.source == MAC && spaceeol(*(InputBufferPtr + i + 1)))
  434.                                         {   cursorx++;
  435.                                             FPutC(FileHandle, ' ');
  436.                                         } else
  437.                                         {   cursorx = 0;
  438.  
  439.                                             if (eol.source == eol.dest)
  440.                                                 FPutC(FileHandle, CR); // pass it through
  441.                                             elif (eol.source == IBM && eol.dest == AMIGA)
  442.                                                 ; // do nothing
  443.                                             elif (eol.source == IBM && eol.dest == MAC)
  444.                                                 FPutC(FileHandle, CR); // pass it through
  445.                                             elif (eol.source == MAC && eol.dest == AMIGA)
  446.                                                 FPutC(FileHandle, LF); // convert from CR to LF
  447.                                             elif (eol.source == MAC && eol.dest == IBM)
  448.                                             {   FPutC(FileHandle, CR); // pass this through
  449.                                                 FPutC(FileHandle, LF); // and add this
  450.                                             } else ; // amiga as source: we never expect CRs
  451.                                     }   }
  452.                                     elif (*(InputBufferPtr + i) == TAB)
  453.                                     {   if (eol.detabulate)
  454.                                         {   gap = (((cursorx / eol.tabsize) + 1) * eol.tabsize) - cursorx;
  455.                                             for (j = 1; j <= gap; j++)
  456.                                                 FPutC(FileHandle, ' ');
  457.                                             cursorx += gap;
  458.                                         } else FPutC(FileHandle, TAB); // no point to cursorx in non-detabulate
  459.                                     } else
  460.                                     {   FPutC(FileHandle, *(InputBufferPtr + i));
  461.                                         cursorx++;
  462.                                 }   }
  463.                                 /* Note that FPutC() returns EOF for errors; this is not currently
  464.                                 checked. */
  465.                                 ok = TRUE;
  466.                                 Close(FileHandle);
  467.                         }   }
  468.                         else
  469.                         {   Close(FileHandle);
  470.                     }   }
  471.                     FreeMem(InputBufferPtr, InputInfoBlock.fib_Size);
  472.         }   }   }
  473.         else
  474.         {   UnLock(FileHandle);
  475.     }   }
  476.  
  477.     if (gui)
  478.     {   if (ok)
  479.             strcat(saystring, "done.");
  480.         else strcat(saystring, "failed!");
  481.  
  482.         SetGadgetAttrs
  483.         (   eol_gadgets[GID_7_ST2], MainWindowPtr, NULL,
  484.             STRINGA_TextVal, saystring,
  485.         TAG_END);
  486.     } else
  487.     {   if (ok)
  488.             Printf("done.\n");
  489.         else Printf("failed!\n");
  490.     }
  491.  
  492.     checkabort(gui);
  493. }
  494.  
  495. AGLOBAL void eol_loop(ULONG gid)
  496. {   STRPTR stringptr;
  497.  
  498.     switch(gid)
  499.     {
  500.     case GID_7_RA1:
  501.         if (!(GetAttr
  502.         (   RADIOBUTTON_Selected, eol_gadgets[GID_7_RA1], (ULONG *) &eol.source
  503.         )))
  504.         {   rq("Unsupported inquiry!"); // should never happen
  505.         }
  506.     break;
  507.     case GID_7_RA2:
  508.         if (!(GetAttr
  509.         (   RADIOBUTTON_Selected, eol_gadgets[GID_7_RA2], (ULONG *) &eol.dest
  510.         )))
  511.         {   rq("Unsupported inquiry!"); // should never happen
  512.         }
  513.     break;
  514.     case GID_7_ST1:
  515.         if (!(GetAttr
  516.         (   STRINGA_TextVal, eol_gadgets[GID_7_ST1], (ULONG *) &stringptr
  517.         )))
  518.         {   rq("Unsupported inquiry!"); // should never happen
  519.         }
  520.         strcpy(eol.pathname, stringptr);
  521.     break;
  522.     case GID_7_BU1:
  523.         strcpy(shared.pathname, eol.pathname);
  524.         multiasl("#?.info");
  525.         strcpy(eol.pathname, shared.pathname);
  526.         SetGadgetAttrs
  527.         (   eol_gadgets[GID_7_ST1], MainWindowPtr, NULL,
  528.             STRINGA_TextVal, eol.pathname,
  529.             TAG_END
  530.         );
  531.     break;
  532.     case GID_7_BU3:
  533.         eol_do();
  534.     break;
  535.     case GID_7_CB1:
  536.         if (!(GetAttr
  537.         (   GA_Selected, eol_gadgets[GID_7_CB1], (ULONG *) &eol.detabulate
  538.         )))
  539.         {   rq("Unsupported inquiry!"); // should never happen
  540.         }
  541.     break;
  542.     case GID_7_CB2:
  543.         if (!(GetAttr
  544.         (   GA_Selected, eol_gadgets[GID_7_CB2], (ULONG *) &eol.unwrap
  545.         )))
  546.         {   rq("Unsupported inquiry!"); // should never happen
  547.         }
  548.     break;
  549.     case GID_7_IN1:
  550.         if (!(GetAttr
  551.         (   INTEGER_Number, eol_gadgets[GID_7_IN1], (ULONG *) &eol.tabsize
  552.         )))
  553.         {   rq("Unsupported inquiry!"); // should never happen
  554.         }
  555.     break;
  556.     default:
  557.     break;
  558. }   }
  559.  
  560. MODULE ABOOL spaceeol(TEXT nextchar)
  561. {   if
  562.     (   nextchar == ' '
  563.      || nextchar == TAB
  564.      || nextchar == LF
  565.      || nextchar == CR
  566.     )
  567.     {   return(FALSE);
  568.     } else return(TRUE);
  569. }
  570.  
  571. AGLOBAL void eol_die(void)
  572. {   IOBuffer[1] = (UBYTE) eol.source;
  573.     IOBuffer[2] = (UBYTE) eol.dest;
  574.     IOBuffer[3] = (UBYTE) eol.detabulate;
  575.     IOBuffer[4] = (UBYTE) eol.tabsize;
  576.     IOBuffer[5] = (UBYTE) eol.unwrap;
  577. }
  578.  
  579. AGLOBAL void eol_config(void)
  580. {   eol.source     = (ULONG) IOBuffer[1];
  581.     eol.dest       = (ULONG) IOBuffer[2];
  582.     eol.detabulate = (ULONG) IOBuffer[3];
  583.     eol.tabsize    = (ULONG) IOBuffer[4];
  584.     eol.unwrap     = (ULONG) IOBuffer[5];
  585. }
  586.  
  587. AGLOBAL ULONG Hook7Func(struct Hook *h, VOID *o, VOID *msg)
  588. {   /* "When the hook is called, the data argument points to the 
  589.     window object and message argument to the IntuiMessage." */
  590.  
  591.     UWORD code, qual;
  592.  
  593.     geta4(); // wait till here before doing anything
  594.  
  595.     code = ((struct IntuiMessage *) msg)->Code;
  596.     qual = ((struct IntuiMessage *) msg)->Qualifier;
  597.  
  598.     switch(code)
  599.     {
  600.     case SCAN_HELP:
  601.         helpabout();
  602.     break;
  603.     case SCAN_ESCAPE:
  604.         if ((qual & IEQUALIFIER_LSHIFT) || (qual & IEQUALIFIER_RSHIFT))
  605.         {   cleanexit(EXIT_SUCCESS);
  606.         } else page = 0;
  607.     break;
  608.     case SCAN_D:
  609.         if (!(qual & IEQUALIFIER_LSHIFT) && !(qual & IEQUALIFIER_RSHIFT))
  610.         {   if (eol.dest < 2)
  611.                 eol.dest++;
  612.             else eol.dest = 0;
  613.         } else
  614.         {   if (eol.dest > 0)
  615.                 eol.dest--;
  616.             else eol.dest = 2;
  617.         }
  618.         SetGadgetAttrs
  619.         (   eol_gadgets[GID_7_RA2], MainWindowPtr, NULL,
  620.             RADIOBUTTON_Selected, eol.dest,
  621.         TAG_END);
  622.         // we must explicitly refresh
  623.         RefreshGadgets((struct Gadget *) eol_gadgets[GID_7_RA2], MainWindowPtr, NULL);
  624.     break;
  625.     case SCAN_O:
  626.         // the gadget is handled automatically by the system, all we need
  627.         // to do is update our internal record of the state of the gadget
  628.         if (!(GetAttr
  629.         (   GA_Selected, eol_gadgets[GID_7_CB1], (ULONG *) &eol.detabulate
  630.         )))
  631.         {   rq("Unsupported inquiry!"); // should never happen
  632.         }
  633.     break;
  634.     case SCAN_P:
  635.         ActivateLayoutGadget(eol_gadgets[GID_7_LY1], MainWindowPtr, NULL, (Object) eol_gadgets[GID_7_ST1]);
  636.     break;
  637.     case SCAN_S:
  638.         if (!(qual & IEQUALIFIER_LSHIFT) && !(qual & IEQUALIFIER_RSHIFT))
  639.         {   if (eol.source < 2)
  640.                 eol.source++;
  641.             else eol.source = 0;
  642.         } else
  643.         {   if (eol.source > 0)
  644.                 eol.source--;
  645.             else eol.source = 2;
  646.         }
  647.         SetGadgetAttrs
  648.         (   eol_gadgets[GID_7_RA1], MainWindowPtr, NULL,
  649.             RADIOBUTTON_Selected, eol.source,
  650.         TAG_END);
  651.  
  652.         // we must explicitly refresh
  653.         RefreshGadgets((struct Gadget *) eol_gadgets[GID_7_RA1], MainWindowPtr, NULL);
  654.     break;
  655.     case SCAN_T:
  656.         ActivateLayoutGadget(eol_gadgets[GID_7_LY1], MainWindowPtr, NULL, (Object) eol_gadgets[GID_7_IN1]);
  657.     break;
  658.     case SCAN_U:
  659.         // the gadget is handled automatically by the system, all we need
  660.         // to do is update our internal record of the state of the gadget
  661.         if (!(GetAttr
  662.         (   GA_Selected, eol_gadgets[GID_7_CB2], (ULONG *) &eol.unwrap
  663.         )))
  664.         {   rq("Unsupported inquiry!"); // should never happen
  665.         }
  666.     break;
  667.     case SCAN_PERIOD:
  668.         strcpy(shared.pathname, eol.pathname);
  669.         multiasl("~(#?.info)");
  670.         strcpy(eol.pathname, shared.pathname);
  671.         SetGadgetAttrs
  672.         (   eol_gadgets[GID_7_ST1], MainWindowPtr, NULL,
  673.             STRINGA_TextVal, eol.pathname,
  674.         TAG_END);
  675.     break;
  676.     default:
  677.     break;
  678.     }
  679.  
  680.     return(1);
  681. }
  682.  
  683.  
  684.